package com.itheima.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

//@WebFilter(urlPatterns = "/*")//拦截所有请求
@Slf4j
public class DemoFilter implements Filter {
    //初始化方法，web服务器启动，创建Filter实例时调用，只调用一次
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("init...");
    }

    //拦截到请求时，调用该方法，可以调用多次
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("拦截到了请求...");
        //放行
        filterChain.doFilter(servletRequest,servletResponse);
    }

    //销毁方法，web服务器关闭时调用，只调用一次
    @Override
    public void destroy() {
        log.info("destroy...");
    }
}
